package com.itzyf.pokemondata.activity

import android.widget.TextView
import com.itzyf.pokemondata.R
import com.qmuiteam.qmui.widget.dialog.QMUIDialog
import com.tydic.baselibrary.activity.BaseActivity
import kotlinx.android.synthetic.main.activity_guild_setting.*

class GuildSettingActivity : BaseActivity() {
    override fun handlerActivity() {
        guildAttackValue.text = sp.getString("guildAttackValue", "0%")
        guildAttackValue.setOnClickListener {
            showGuildDialog(it as TextView)
        }
        //公会双防
        guildDefenseValue.text = sp.getString("guildDefenseValue", "0%")
        guildDefenseValue.setOnClickListener {
            showGuildDialog(it as TextView)
        }
    }

    override fun getContentViewId() = R.layout.activity_guild_setting

    override fun getToolbarTitle() = "公会加成设置"

    /**
     * 公会加成
     */
    private fun showGuildDialog(view: TextView) {
        //创建一个数组
        val guilds = ArrayList<String>(26)
        //数组中放入1%-15%
        for (i in 0..25) {
            guilds.add("$i%")
        }
        //创建一个对话框，把上面的数据放进去
        val builder = QMUIDialog.CheckableDialogBuilder(this)
            .setTitle("请选择")
            .addItems(guilds.toTypedArray()) { dialog, which ->
                if (view == guildAttackValue)
                    sp.edit().putString("guildAttackValue", guilds[which]).apply()
                else
                    sp.edit().putString("guildDefenseValue", guilds[which]).apply()
                view.text = guilds[which] //提交选中的值，并关闭
                dialog.dismiss()
            }
        builder.show() //显示对话框
    }
}